package top.zhangjianyong.blog.response;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.io.Serial;
import java.util.List;
import top.zhangjianyong.blog.utils.EntityUtil;

/**
 * @author zhangjianyong
 * @since 2024/8/30 下午12:31
 */
public class PageDTO<T> extends Page<T> {

  @Serial
  private static final long serialVersionUID = 1L;

  private PageDTO(Page<?> page, List<T> records) {
    super(page.getCurrent(), page.getSize(), page.getTotal(), page.searchCount());
    this.records = records;
  }

  public static <T, U extends T> PageDTO<U> getPage(Page<T> page, Class<U> clazz) {
    List<U> us = EntityUtil.entity2DTO(page.getRecords(), clazz);
    return new PageDTO<>(page, us);
  }

  public static <T> PageDTO<T> getPage(Page<?> page, List<T> records) {
    return new PageDTO<>(page, records);
  }
}
